/**
 * Created by Administrator on 2016/7/14.
 */
var user_token =  sessionStorage.user_token;
$(document).ready(function() {
    new Vue({
        el: '#app',
        data: {
            message: ''
        }
    })
    var doctor = '<section class="mainPart" v-for="item in items" ><section class="docListMember"><img v-if="item.nic_thumb != \'\'" v-bind:src="item.nic_thumb"><img v-if="item.nic_thumb ==\'\'" src="../images/userDefault.png"><section class="rightPart"><p><span>{{item.name}}</span><span>{{item.zhiwu}}</span></p><p><span>{{item.hospital_name}}</span><span>{{item.keshi}}</span></p><p><img src="../images/star.png"><span>{{item.score}}</span><span>接诊量: {{item.response_times}}</span></p><p>{{item.shan_chang}}</p><p class="id">{{item.d_id}}</p></section></section></section>'
    var oldvalue = $("header p:last-child").text();;
    $('header input').keyup(function(){
        var searchVal = $("header p:last-child").text();

        if(oldvalue !=searchVal&&searchVal!=''){
            $('#mainPart').empty();
            oldvalue = searchVal;
            $(".total").css("display","none");
            $(".header").css("display","block");
            $(".body").css("display","block");
            $.post(commonval+"/search", {
                name: searchVal,
                //user_token:user_token,
                device:"wap",
            }, function (data) {
                if (data.status == 0) {
                    createWindow("查询医生信息失败");
                } else {
                    $('#mainPart').append(doctor);
                    var consultList = new Vue({
                        el: '#mainPart' ,
                        data: {
                            items: data.data.doctor_list
                        }
                    });
                    $(".docListMember").css("display","block");
                    $(".docListMember").click(function(){
                        var id = $(this).children(".rightPart").children("p:last-child").text();
                        location.href="doctorInfo.html?id="+id;
                    })
                }
            });
        }else if(searchVal==''){
            $('#mainPart').empty();
            $(".total").css("display","block");
            $(".header").css("display","none");
            $(".body").css("display","none");
        }
    })

    $("header p").click(function () {
       history.go(-1);
    })
    //展示常用医生
    $.post(commonval+"/search_click", {
        user_token:user_token,
        device:"wap",
    }, function (data) {
        if(data.status == 1){
            if(data.data.doctor_list.length>3){
                $("#center").css("padding-bottom","328px");
            }
            $(".total").css("display","block");
            var dairyBook = new Vue({
                el: '#center',
                data: {
                    items: data.data.doctor_list
                }
            });
            $(".center a").click(function(){
                var id = $(this).next().text();
                location.href="doctorInfo.html?id="+id;
            })
        }else{
            createWindow("获取推荐医生失败");
        }
    });
});

//定义展示搜索结果列表方法


//定义黑色弹窗方法
function createWindow(msg) {
    var window =$("<section class='showMsg'></section>");
    var show = "<p>"+msg+"</p>";
    window.append(show);
    $("body").append(window);
    setTimeout("$('.showMsg').remove()",3000);
}


